home *** CD-ROM | disk | FTP | other *** search
/ Delphi Developer's Kit 1996 / Delphi Developer's Kit 1996.iso / power / srctt26 / previnst.pas < prev    next >
Pascal/Delphi Source File  |  1995-12-22  |  896b  |  43 lines

  1. unit PrevInst;
  2.  
  3. interface
  4.  
  5. uses WinProcs, WinTypes, SysUtils;
  6.  
  7. type
  8.   PHWnd = ^HWnd;
  9.  
  10. function EnumFunc(Wnd : HWnd; TargetWindow : PHWnd): Bool; export;
  11. procedure ActivatePreviousInstance;
  12.  
  13. implementation
  14.  
  15. function EnumFunc(Wnd : HWnd; TargetWindow : PHWnd): Bool;
  16. var
  17.   ClassName : array [0..30] of char;
  18. begin
  19.   Result := True;
  20.   if GetWindowWord(Wnd,GWW_HINSTANCE) = HPrevInst then begin
  21.     GetClassName(Wnd,ClassName,30);
  22.     if StrIComp(ClassName,'TApplication') = 0 then begin
  23.       TargetWindow^ := Wnd;
  24.       Result := False;
  25.     end;
  26.   end;
  27. end;
  28.  
  29. procedure ActivatePreviousInstance;
  30. var
  31.   PrevInstWnd : HWnd;
  32. begin
  33.   PrevInstWnd := 0;
  34.   EnumWindows(@EnumFunc,Longint(@PrevInstWnd));
  35.   if PrevInstWnd <> 0 then
  36.     if IsIconic(PrevInstWnd) then
  37.       ShowWindow(PrevInstWnd,SW_RESTORE)
  38.     else
  39.       BringWindowToTop(PrevInstWnd);
  40. end;
  41.  
  42. end.
  43.